﻿using gAMS_Sacombank.AssetService;
using gAMS_Sacombank.Resources;
using mvvmCommon;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Xml.Linq;

namespace gAMS_Sacombank.CommonClass
{
    public static class CurrentSystemLogin
    {
        public static TL_USER CurrentUser { get; set; }
        public static Dictionary<string, TL_SYSROLEDETAIL> Roles { get; set; }
        public static bool IsAppFunction = false;
        public const string SessionKeys = "CurrentUser";
    }

    public class ImageConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            MemoryStream memStream = new MemoryStream((byte[])value);
            memStream.Seek(0, SeekOrigin.Begin);
            BitmapImage empImage = new BitmapImage();
            empImage.SetSource(memStream);
            return empImage;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class FormatMoneyVN : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return MyHelper.Format_Price(Math.Round((decimal)value, 0).ToString());
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class MyStaticClass
    {
        public static ObservableCollection<ItemYesNo> AssetResourceData = new ObservableCollection<ItemYesNo>()
                {
                    new ItemYesNo(){ Id="B", Name=AssetResource.lblBuy},
                    new ItemYesNo(){ Id="R", Name=AssetResource.lblRent},
                    new ItemYesNo(){ Id="D", Name=AssetResource.lblDonation}
                };

        public static decimal ValidateMoney(string value)
        {
            decimal temp = 0;
            if (!decimal.TryParse(value, out temp))
                temp = 0;
            return Math.Round(temp, 0);
        }

        
        private static decimal GetConstant(int? month)
        {
            if (month <= 4 * 12) return 3 / 2;
            else if (month <= 6 * 12) return 2;
            else return 5 / 2;
        }
    }
       

    public class ConvertContentXML : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string content = "";
            foreach (var item in (value as XElement).Elements())
            {
                switch (item.Attribute("Event").Value)
                {
                    case "RE":
                        content += AssetResource.lblNoteAdd + ": " + AssetResource.AssetValue + ": " + MyHelper.Format_Price(item.Element("Value").Value) + "; "
                            + AssetResource.lblTimeDiscount + ": " + item.Element("TimeDiscount").Value + " (" + AssetResource.lblMonth + ")";
                        break;
                    case "AT":
                        content += AssetResource.lblTranTo + ": " + item.Element("Infra_Id").Value
                            + " - " + item.Element("Area_Id").Value
                            + " - " + item.Element("Room_Id").Value
                            + "; " + AssetResource.Count + ": " + item.Element("Count").Value;
                        break;
                    case "GR":
                        content += AssetResource.Count + ": " + item.Element("Count").Value
                            + "; " + AssetResource.lblGuaranteeValue + ": " + MyHelper.Format_Price(item.Element("Value").Value);
                        break;
                }
            }
            return content;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class MyPost
    {
        public string ReportName { get; set; }
        public string Query { get; set; }
        public string TableName { get; set; }

        public string TypeReport { get; set; }
        public string Type { get; set; }

        public override string ToString()
        {
            return string.Format("?ReportName={0}&Query={1}&TableName={2}&TypeReport={3}&Type={4}",
                ReportName, Query, TableName, TypeReport, Type);
        }
    }

}
